package play.modules.plovr;

import org.plovr.CompilationServer;
import org.plovr.CompileRequestHandler;
import org.plovr.Config;
import play.mvc.Http;

import java.io.File;
import java.io.IOException;

/**
 * Extend CompileRequestHandler so we can call doGet, which is a protected method
 * author: Dallan Quass
 */
public class PlayCompileRequestHandler extends CompileRequestHandler {

   public PlayCompileRequestHandler(CompilationServer server) {
      super(server);
   }

   public String compile(String id, Http.Request request) throws IOException {
      DummyHttpExchange exchange = new DummyHttpExchange(request);
      Config config = server.getConfigById(id);
      super.doGet(exchange, null, config);
      return exchange.getResponseBodyAsString(config.getOutputCharset());
   }
}
